<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ page import="com.beaut.project.util.StaticData" %>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
	Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
	String person_id = String.valueOf(sessionMap.get("id"));
	String person = String.valueOf(sessionMap.get("truename"));
%>
<html>
	<head>
		<title>分包借款管理</title>
	
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
			.tdg{
			padding-top:10px;
			padding-bottom:5px;
			font-size: 12px;
			background-color: #c0ebd7;
			width:20%;
		}
		.tdb{
			padding:5px;
			width:30%;
		}
		</style>
	<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery("#searchValue").keypress(function(e) { 
	    	// 回车键事件 
	     	if(e.which == 13) { 
	     		 doSearch();
	       	} 
		});
		
		jQuery('#fb_advances_id').combogrid({
			idField:"id",
			textField:"worker_company",
			title:'分包商资料',
			panelWidth:550,
			panelHeight:400,
			rownumbers:true,
			url:'<%=contextPath%>/springMVC/crm/listPageWorker',
			loadMsg:'正在加载数据，请稍后......',
			fitColumns:true,
			frozenColumns:[[
			    {title:'主键',field:'id',hidden:true}
			]],
			columns:[[
				{title:'分包商类别',field:'type_id',width:200,align:'center',formatter:function(value,rowData,rowIndex){
					return typeArr[rowData.type_id];
				}},
				{title:'公司名称',field:'worker_company',width:200,align:'center'},
				{title:'负责人',field:'worker_person',width:200,align:'center'},
				{title:'联系方式',field:'contact',width:200,align:'center'}
			]],
			pageSize:10,
			pageList : [10,50,100],  
			pagination:true,
			toolbar:'#tb1',
			onChange:function(){
				var row = jQuery('#fb_advances_id').combogrid("grid").datagrid('getSelected');
				jQuery('#fb_advances').val(row.worker_company);
			}
		});
		var typeArr=new Array("内部班组","外部分包商");
		jQuery("#table").datagrid({
			title:"班组借款",
			iconCls:'icon-zc',
			loadMsg:'正在加载数据，请稍后......',
			url:'<%=contextPath %>/springMVC/gd/listPageGdNewAdvances',
			rownumbers:true,
			fitColumns:true,
			nowrap:false,
			idField:'id',
			frozenColumns:[[
			      //{field:'ck',checkbox:true},
			      {title:'主键',field:'id',hidden:true}
			]],
			columns:[[
				{title:'班组',field:'fb_advances',width:100,align:'center'},
				{title:'日期',field:'operation_date',width:100,align:'center',sort:true},
				{title:'借款金额',field:'sumMoney',width:100,align:'center',formatter:function(val,rowData,rowIndex){
			        if(val!=null)
			            return val.toFixed(2);
			   		}
			   	},
				{title:'结余本金',field:'on_money',width:100,align:'center',formatter:function(val,rowData,rowIndex){
			        if(val!=null)
			            return val.toFixed(2);
			   		}
			   	},
			   	{title:'利息',field:'lx',width:100,align:'center',formatter:function(val,rowData,rowIndex){
			   		if(rowData.sumMoney>0){
			            return (rowData.sumMoney-rowData.on_money).toFixed(2);
			         }else{
			         	return 0;
			         }
			      }
			   	},
				{title:'利率',field:'rate',width:100,align:'center'},
				{title:'已还金额',field:'already_money',width:100,align:'center',formatter:function(val,rowData,rowIndex){
			        if(val!=null)
			            return val.toFixed(2);
			   		}
			   	},
				{title:'当前状态',field:'status',width:60,align:'center',hidden:true},
				{title:'当前状态',field:'status_desc',width:60,align:'center'},
				{title:'经办人',field:'person_name',width:100,align:'center'},
				{title:'摘要',field:'remark',width:200,align:'center'},
				{title:'操作',field:'edit',width:100,align:'center',formatter:function(value,rowData,rowIndex){
					if(rowData.status == '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditPay(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteGDFinance('"+rowData.id+"');\"/>&nbsp;&nbsp;"
                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='提交确认' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/>";
					}
					if(rowData.status == '<%=com.beaut.project.util.StaticData.NO_PASS%>'){
						return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditPay(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
						      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='提交确认' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/>";
					}
                	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:addOrEditPay(2,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
				      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.GD_NEW_ADVANCES_SHENPI%>")+"','"+rowData.id+"');\"/>";

				}}
			]],
			pageSize:10,
			pageList : [10,50,100],  
			pagination:true,
			onLoadSuccess:function(rtJson){
				if(rtJson.rtState== '1')
				{
					$.messager.alert('提示',rtJson.rtMsrg);
				}
			}
		});
		
		
			  
			});
	  
		
		function addOrEditPay(type,id){
			if(type==0){
				openDialogResize("<%=contextPath %>/springViews/finance/addOrEditWorkerLoan.jsp?callback=rtCallBack",1000, 800);
			}else if(type==1){
				openDialogResize("<%=contextPath %>/springViews/finance/addOrEditWorkerLoan.jsp?callback=rtCallBack&id="+id,1000, 800);
			}else {
				openDialogResize("<%=contextPath %>/springViews/finance/addOrEditWorkerLoan.jsp?callback=rtCallBack&isShow=1&id="+id,1000, 800);
			}
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function deleteRows(){
			var rows=jQuery('#table').datagrid('getSelections');
			var deleteVar="";
			if(rows.length==0)
			{
				jQuery.messager.alert('提示','选中要删除的记录');  
				return ;
			}
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					deleteVar+=rows[i].id;
				}else
				{
					deleteVar+=rows[i].id+",";
				}
			}
			jQuery.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					jQuery.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/deleteGdNewAdvances",
						data:"ids="+deleteVar,
						dataType:"json",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								jQuery.messager.alert('提示：',rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function deleteGDFinance(id){
			var rows=jQuery('#table').datagrid('getSelections');
			jQuery.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					jQuery.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/deleteGdNewAdvances",
						data:"ids="+id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function shenpi(obj,id){
	    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	      var flowBusinessUrl="<%=contextPath %>/springViews/gd/addOrEditGdAdvances.jsp?callback=rtCallBack&isShow=1&id="+id;
	      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.GD_NEW_ADVANCES_SHENPI%>")+"&businessId="+id;
	      jQuery(obj).hide();
	      jQuery.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							jQuery(obj).show();
						}
					});
	       
	    } 
		
		function doSearch() {
			var searchValue = jQuery('#searchValue').val();
			var start_time=$('#start_time').datebox('getValue');  
			var end_time=$('#end_time').datebox('getValue');  
			$('#table').datagrid('load', {
				start_time:start_time,
				end_time:end_time,
				searchValue:searchValue
			});
		}
			function ExcelOut(){
			 		var start_time=$('#start_time').datebox('getValue');  
					var end_time=$('#end_time').datebox('getValue');  
					var searchValue = jQuery('#searchValue').val();
				var param = "searchValue="+encodeURIComponent(searchValue)+"&start_time="+start_time+"&end_time="+end_time;
				window.open('<%=contextPath %>/springMVC/excel/listNewAdvances?'+param);
			}
	</script>
	</head>
	<body style="height: 97%">
		
					
							<div id="table"  data-options="toolbar:'#tb',fit:true"></div>  
								<div id="tb" style="padding:3px;height:auto">
								<div style="float:left;">
								<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addOrEditPay(0);">添加借款单</a>
							</div>
						<div align="right">
							开始时间：<input id="start_time" name="start_time" class="easyui-datebox" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" />
							查询条件：<input id="searchValue" name="searchValue" style="width:150px" title="班组/标题"  placeholder="班组/标题"/>
								<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
							<input type='button'  style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-excel' title='导出Excel' onclick='ExcelOut()'/>
						
						</div>
					</div>
	</body>
</html>